export default {
  data() {
    return {
    }
  },
  methods: {
    /**
     * 零售价校验
     * @params sellPrice 零售价
     * @params goodsSource 商品来源
     * @params supplyAllianceSellMinPrice 供货联盟价格下限
     * @params supplyAllianceSellMaxPrice 供货联盟价格上限
     * @params supplyAllianceSellPriceType 供货联盟价格类型
     * @return 错误信息
     */
    sellPriceCheck(sellPrice, goodsSource, supplyAllianceSellMinPrice, supplyAllianceSellMaxPrice, supplyAllianceSellPriceType) {
      const label = '零售价'
      const nullFlag = Number.isNaN(parseFloat(sellPrice))
      if (nullFlag) {
        return '请输入' + label
      }
      if (goodsSource === '3') {
        const errorMsg = this.checkPriceBySupplyAlliance(sellPrice, supplyAllianceSellMinPrice, supplyAllianceSellMaxPrice, supplyAllianceSellPriceType)
        if (errorMsg) {
          return label + errorMsg
        }
      }
      return ''
    },

    /**
     * 样品价校验
     * @params specimenPrice 零售价
     * @params selectionGoodsType 选品小程序flag
     * @params goodsSource 商品来源
     * @params supplyAllianceSellMinPrice 供货联盟价格下限
     * @params supplyAllianceSellMaxPrice 供货联盟价格上限
     * @params supplyAllianceSellPriceType 供货联盟价格类型
     * @return 错误信息
     */
    specimenCheck(specimenPrice, selectionGoodsType, goodsSource, supplyAllianceSellMinPrice, supplyAllianceSellMaxPrice, supplyAllianceSellPriceType) {
      const label = '样品价'
      const nullFlag = Number.isNaN(parseFloat(specimenPrice))
      if (selectionGoodsType === 1 && nullFlag) {
        return '请输入' + label
      }
      if (!nullFlag) {
        if (goodsSource === '3') {
          const errorMsg = this.checkPriceBySupplyAlliance(specimenPrice, supplyAllianceSellMinPrice, supplyAllianceSellMaxPrice, supplyAllianceSellPriceType)
          if (errorMsg) {
            return label + errorMsg
          }
        }
      }
      return ''
    },

    /**
     * 零售运费校验
     * @params postFeeType 运费类型
     * @params postFee 运费
     * @params deliveryTemplateId 运费模板
     * @return 错误信息
     */
    postFeeTypeCheck(postFeeType, postFee, deliveryTemplateId) {
      switch (postFeeType) {
        case '10':
          if (Number.isNaN(parseFloat(postFee))) {
            return '请输入运费'
          }
          break
        case '11':
          if (!deliveryTemplateId) {
            return '请选择运费模板'
          }
          break
      }
      return ''
    },

    /**
     * 分销运费校验
     * @params distributePostFeeType 运费类型
     * @params distributePriceFee 运费
     * @params distributeDeliveryTemplateId 运费模板
     * @return 错误信息
     */
    distributePostFeeTypeCheck(distributePostFeeType, distributePriceFee, distributeDeliveryTemplateId) {
      switch (distributePostFeeType) {
        case '10':
          if (Number.isNaN(parseFloat(distributePriceFee))) {
            return '请输入运费'
          }
          break
        case '11':
          if (distributeDeliveryTemplateId) {
            return '请选择运费模板'
          }
          break
      }
      return ''
    },

    /**
     * 批发运费校验
     * @params wholesalePostFeeType 运费类型
     * @params wholesalePostFee 运费
     * @params wholesaleDeliveryTemplateId 运费模板
     * @return 错误信息
     */
    wholesalePostFeeTypeCheck(wholesalePostFeeType, wholesalePostFee, wholesaleDeliveryTemplateId) {
      switch (wholesalePostFeeType) {
        case '10':
          if (Number.isNaN(parseFloat(wholesalePostFee))) {
            return '请输入运费'
          }
          break
        case '11':
          if (!wholesaleDeliveryTemplateId) {
            return '请选择运费模板'
          }
          break
      }
      return ''
    },

    /**
     * 供货联盟商品价格统一校验
     * @params price 价格
     * @params supplyAllianceSellMinPrice 供货联盟价格下限
     * @params supplyAllianceSellMaxPrice 供货联盟价格上限
     * @params supplyAllianceSellPriceType 供货联盟价格类型
     * @return 错误信息
     */
    checkPriceBySupplyAlliance(price, supplyAllianceSellMinPrice, supplyAllianceSellMaxPrice, supplyAllianceSellPriceType) {
      const nullFlag = Number.isNaN(parseFloat(price))
      var floatPrice = nullFlag ? 0 : parseFloat(price)
      var floatSupplyAllianceSellMinPrice = parseFloat(supplyAllianceSellMinPrice)
      var floatSupplyAllianceSellMaxPrice = parseFloat(supplyAllianceSellMaxPrice)
      let errorMsg
      switch (supplyAllianceSellPriceType) {
        case 1:
          if (floatPrice < floatSupplyAllianceSellMinPrice || floatPrice > floatSupplyAllianceSellMaxPrice) {
            errorMsg = '应该在限定零售价范围之内'
          }
          break
        case 2:
          if (floatPrice !== floatSupplyAllianceSellMinPrice) {
            errorMsg = '应等于限定零售价'
          }
          break
      }
      return errorMsg
    },
    /**
     * 批发价校验
     * @params wholesalePrice 批发价
     * @params goodsSource 商品来源
     * @params supplyAllianceMinWholesalePrice 供货联盟：最低批发价
     * @params supplyAllianceMaxWholesalePrice 供货联盟：最大批发价
     * @params supplyAllianceWholesalePriceType 供货联盟：批发模式(1-限定批发价范围；2-限定批发价；3-不限定批发价
     * @params supplyAllianceIsEnableWholesaleModel 供货联盟：是否启用批发模式：0不启用 1启用
     * @return 错误信息
     */
    wholesalePriceCheck(wholesalePrice, goodsSource, supplyAllianceMinWholesalePrice, supplyAllianceMaxWholesalePrice, supplyAllianceWholesalePriceType, supplyAllianceIsEnableWholesaleModel) {
      const label = '批发价'
      const nullFlag = Number.isNaN(parseFloat(wholesalePrice))
      if (nullFlag) {
        return '请输入' + label
      }
      if (goodsSource === '3') {
        var floatPrice = parseFloat(wholesalePrice)
        var floatSupplyAllianceMinWholesalePrice = parseFloat(supplyAllianceMinWholesalePrice)
        var floatSupplyAllianceMaxWholesalePrice = parseFloat(supplyAllianceMaxWholesalePrice)
        let errorMsg
        if (supplyAllianceIsEnableWholesaleModel === 1) {
          switch (supplyAllianceWholesalePriceType) {
            case 1:
              if (floatPrice < floatSupplyAllianceMinWholesalePrice || floatPrice > floatSupplyAllianceMaxWholesalePrice) {
                errorMsg = '应该在限定批发价范围之内'
              }
              break
            case 2:
              if (floatPrice !== floatSupplyAllianceMinWholesalePrice) {
                errorMsg = '应等于限定批发价'
              }
              break
          }
          if (errorMsg) {
            return label + errorMsg
          }
        }
        return ''
      }
    }
  }
}
